package odontologico.dao.base.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

/**
 * 
 * @author LuisEduardo
 *
 */
public class EntityManagerUtils {

	private static EntityManagerFactory entityManagerFactory;

	@PersistenceContext(unitName = "odontologico")
	private static EntityManager entityManager;

	private static final String PERSISTENCE_UNIT_NAME = "odontologico";

	public EntityManagerUtils() {
		super();
	}

	public static EntityManager getEntityManager() {
		if (entityManager == null) {
			crearEntityManager();
		}
		return entityManager;
	}

	private static void crearEntityManager() {
		entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
		entityManager = entityManagerFactory.createEntityManager();
	}

}
